﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

using SharpGL.SceneGraph.Core;
using SharpGL.SceneGraph.Helpers;

namespace SharpGL.SceneGraph.Primitives
{
    /// <summary>
    /// Add to <see cref="Polyline"/> color and line width parameters.
    /// </summary>
    [Serializable]
    public class ParamPolyline : Polyline, IDeepCloneable<Polyline>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Polyline"/> class.
        /// </summary>
        public ParamPolyline() 
		{
			Name = "Polyline";

            LineWidth = 1.0f;
            Color = new GLColor(1.0f, 1.0f, 1.0f, 1.0f);
		}
        //--------------------------------------------------------------------------------

        /// <summary>
        /// Perform all rendering operation to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        protected override void InternalRender(OpenGL gl, RenderMode renderMode)
        {
            // Push all attributes, disable lighting and depth testing.
            /*gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.DepthFunc(OpenGL.GL_ALWAYS);*/
            
            // Set line width
            gl.LineWidth(LineWidth);

            // Begin drawing a polyline.
            gl.Begin(OpenGL.GL_LINE_STRIP);
            {
                // Set color
                gl.Color(Color);
                // Set normal
                gl.Normal(0.0f, 0.0f, 1.0f);
                foreach (var vertex in vertices)
                {
                    // Set the vertex.
                    gl.Vertex(vertex);
                }
            }
            gl.End();

            // Restore attributes.
            //gl.PopAttrib();
        }
        //--------------------------------------------------------------------------------

        public float LineWidth
        {
            get;
            set;
        }

        public GLColor Color
        {
            get;
            set;
        }
    }
}
